﻿//修复ligergrid
var onSuccess = true;
function GridNoData(Obj, flag) {
    if (flag != undefined) {
        onSuccess = flag;
    }
    var grid = $(Obj).ligerGrid({
        onSuccess: onSuccess ? function (data) {
            onSuccess = false;
            if ((data.Rows == null || data.Rows.length == 0)) {
                var gridHeaderInner = grid.gridview2[0].children[0].children[0];
                $(gridHeaderInner).width($(gridHeaderInner).width() - 40);
                var gridBodyInner = grid.gridbody[0].children[0];
                $(gridBodyInner).width($(gridHeaderInner).width());
                try {
                    grid.reRender();
                }
                catch (err) { }
            }
        } : null
    });
}

//判断是否为空
function IsEmpty(strings) {
    if (typeof (strings) == "undefined" || strings == "undefined" || strings == null || strings == undefined || strings.toString().length <= 0) {
        return true;
    }
    return strings.toString().replace(/(^\s*)|(\s*$)/g, "").length == 0;
}

//判断是否数字
function validationNumber(e, num) {
    var regu = /^[0-9]+\.?[0-9]*$/;
    if (e.value != "") {
        if (!regu.test(e.value)) {
            e.value = e.value.substring(0, e.value.length - 1);
            e.focus();
        } else {
            if (num == 0) {
                if (e.value.indexOf('.') > -1) {
                    e.value = e.value.substring(0, e.value.length - 1);
                    e.focus();
                }
            }
            if (e.value.indexOf('.') > -1) {
                if (e.value.split('.')[1].length > num) {
                    e.value = e.value.substring(0, e.value.length - 1);
                    e.focus();
                }
            }
        }
    }
}

//文本框默认值
function placeholder() {
    $(".ipt").each(function () {
        $(this).val($(this).attr("datavalue")).addClass("inp");
        $(this).focus(function () {
            if ($(this).val() == $(this).attr("datavalue")) {
                $(this).val("").removeClass("inp");
            }

        })
        $(this).blur(function () {
            if ($(this).val() == "" || $(this).val() == $(this).attr("datavalue")) {
                $(this).val($(this).attr("datavalue")).addClass("inp");
            }
        })
    });
}

//时间格式化问题
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份   
        "d+": this.getDate(), //日   
        "H+": this.getHours(), //小时   
        "m+": this.getMinutes(), //分   
        "s+": this.getSeconds(), //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds() //毫秒   
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//获取URL参数
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return "";
}

//打开新的tab
function f_addTab(tabid, text, url) {
    top.tab.addTabItem({ tabid: tabid, text: text, url: url });
}

//关闭dialog
function closeDialog() {
    frameElement.dialog.close();//关闭dialog
}

//判断是否是日期格式
function IsValidDate(DateStr) {
    var sDate = DateStr.replace(/(^\s+|\s+$)/g, '');//去两边空格; 
    if (sDate == '') {
        return true;
    }
    //如果格式满足YYYY-(/)MM-(/)DD或YYYY-(/)M-(/)DD或YYYY-(/)M-(/)D或YYYY-(/)MM-(/)D就替换为'' 
    //数据库中，合法日期可以是:YYYY-MM/DD(2003-3/21),数据库会自动转换为YYYY-MM-DD格式 
    var s = sDate.replace(/[\d]{ 4,4 }[\-/]{1}[\d]{1,2}[\-/]{1}[\d]{1,2}/g, '');
    if (s == '') {//说明格式满足YYYY-MM-DD或YYYY-M-DD或YYYY-M-D或YYYY-MM-D 
        var t = new Date(sDate.replace(/\-/g, '/'));
        var ar = sDate.split(/[-/:]/);
        if (ar[0] != t.getYear() || ar[1] != t.getMonth() + 1 || ar[2] != t.getDate()) {//alert('错误的日期格式！格式为：YYYY-MM-DD或YYYY/MM/DD。注意闰年。'); 
            return false;
        }
    } else {//alert('错误的日期格式！格式为：YYYY-MM-DD或YYYY/MM/DD。注意闰年。'); 
        return false;
    }
    return true;
}

//导出Excel
function Export(url) {
    var form = $("<form>");
    form.attr('style', 'display:none');
    form.attr('target', '');
    form.attr('method', 'post');
    form.attr('action', url);
    $('body').append(form);
    form.submit();
    form.remove();
}

//获取当前日期
function CurentDate() {
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var clock = year + "-";
    if (month < 10) clock += "0";
    clock += month + "-";
    if (day < 10) clock += "0";
    clock += day;
    return (clock);
}

//获取当前时间
function CurentDateTime() {
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var clock = year + "-";
    if (month < 10) clock += "0";
    clock += month + "-";
    if (day < 10) clock += "0";
    clock += day + " ";
    if (hh < 10) clock += "0";
    clock += hh + ":";
    if (mm < 10) clock += '0';
    clock += mm;
    return (clock);
}